package com.um.jdy.platform.station.controller;

import com.um.jdy.common.device.entity.dto.StationDTO;
import com.um.jdy.common.device.entity.po.Station;
import com.um.jdy.common.device.entity.vo.StationVO;
import com.um.jdy.platform.station.entity.dto.EditStationDTO;
import com.um.jdy.platform.station.entity.dto.StationPageDTO;
import com.um.jdy.platform.station.entity.vo.EditStationVO;
import com.um.jdy.platform.station.entity.vo.StationItemVO;
import com.um.jdy.platform.station.manager.StationManager;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理类：站场
 *
 * @author cs
 * 日期 2023/5/24
 * 版权所有 广州优匠科技有限公司
 */
@Api(tags = "网点管理")
@Validated
@RestController
@RequestMapping("/api/v1/cms/station")
@ApiPermission("station")
@TokenRequired
public class StationController extends BaseController<StationManager> {

    /**
     * 查询分页
     * @param params
     * @return
     */
    @ApiPermission("page")
    @ApiOperation("分页查询")
    @PostMapping("/page")
    public Response<Page<StationItemVO>> getStationPage(@RequestBody StationPageDTO params){
        PageParams pageParams = params.toPageParams(new String[]{"name","platformMerchantId"},new String[]{"s.name","s.platform_merchant_id"},"s.create_time","beginTime","endTime");
        return manager.getStationPage(pageParams);
    }

    @ApiOperation("列表")
    @GetMapping({"list"})
    public Response<List<StationVO>> list() {
        return manager.list();
    }

    @ApiOperation("列表")
    @GetMapping({"list/{id}"})
    public Response<List<StationVO>> listByMerchant(@PathVariable String id) {
        return manager.listByMerchant(id);
    }

    @ApiPermission("add")
    @ApiOperation("新增")
    @PostMapping
    public Response<Station> add(@RequestBody EditStationDTO dto) {
        return manager.addEntity(dto);
    }

    @ApiPermission("get")
    @ApiOperation("查询")
    @GetMapping({"{id}"})
    public Response<EditStationVO> get(@PathVariable String id) {
        return manager.get(id);
    }

    @ApiPermission("update")
    @ApiOperation("更新")
    @PutMapping({"{id}"})
    public Response<Station> update(@PathVariable String id, @RequestBody EditStationDTO dto) {
        return manager.updateEntity(id, dto);
    }

    @ApiPermission("delete")
    @ApiOperation("删除")
    @DeleteMapping({"{id}"})
    public Response<Object> delete(@PathVariable String id) {
        return manager.delete(id);
    }

    @ApiPermission("delete_all")
    @ApiOperation("批量删除")
    @DeleteMapping
    public Response<Object> deleteIds(@ApiParam(value = "删除的id",required = true) @RequestBody List<String> ids) {
        return manager.deleteIds(ids);
    }

}
